#ifndef PAGE_CONTROL_H
#define PAGE_CONTROL_H

#include <QWidget>
#include <QTimer>
#include <QVariantMap>

class DataMonitor;

namespace Ui {
class Page_control;
}

class Page_control : public QWidget
{
    Q_OBJECT

public:
    explicit Page_control(QWidget *parent = nullptr);
    ~Page_control();

    void setDataMonitor(DataMonitor *dataMonitor);
    void updateSensorDataFromSerial(const QVariantMap &sensorData);

    // ✅ 新增：从告警管理更新蜂鸣器状态
    void updateBuzzerStatusFromAlert(bool isOn);

private slots:
    void onLedBrightnessChanged(int value);
    void onLedSliderReleased();
    void sendLedBrightnessCommand();

    void onFanSpeedChanged(int value);
    void onFanSliderReleased();
    void sendFanSpeedCommand();
    void onFanReverseToggle(bool checked);

    void onQuickCameraToggle(bool checked);
    void onQuickBuzzerToggle(bool checked);

    void updateSensorDataSimulation();

private:
    Ui::Page_control *ui;
    DataMonitor *m_dataMonitor;

    QTimer *m_ledBrightnessTimer;
    QTimer *m_fanSpeedTimer;

    int m_pendingLedBrightness;
    int m_pendingFanSpeed;

    // ✅ 新增：记录蜂鸣器状态
    bool m_buzzerState;

    void initializeDeviceStates();
    void setupConnections();
    void startSensorTimer();

    void sendControlCommand(const QString &deviceType, int deviceId,
                           const QString &action, const QJsonObject &params);

    void updateLedStatus(int brightness);
    void updateFanStatus(int speed);

    // ✅ 新增：更新蜂鸣器UI状态
    void updateBuzzerUI(bool isOn);
};

#endif // PAGE_CONTROL_H
